package view;

import com.alee.laf.WebLookAndFeel;
import control.CityHandler;
import control.DatabaseConnection;
import control.DateUtil;
import control.DriverHandler;
import control.GoodsPriceHandler;
import control.RouteHandler;
import control.ShipmentHandler;
import control.TruckHandler;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import model.City;
import model.Driver;
import model.Route;
import model.Truck;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Annette
 */
public class MainGUI extends javax.swing.JFrame {

    private DatabaseConnection databasse;
    private Route route;
    private String pickUpName;
    private String pickUpAddress;
    private String pickUpZipCode;
    private String pickUpCity;
    private String deliveryName;
    private String deliveryAddress;
    private String deliveryZipCode;
    private String deliveryCity;
    private final Border emptyTextFieldBorder;
    private final Border emptyComboBoxBorder;
    private final Border redLineBorder;
    private int count;

    /**
     * Creates new form NewJFrame
     */
    public MainGUI() {
        redLineBorder = BorderFactory.createLineBorder(Color.red);
        route = null;
        initComponents();
        emptyComboBoxBorder = BorderFactory.createEmptyBorder(3, 3, 3, 3);
        emptyTextFieldBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
        jLOrderConfirm.setVisible(false);
        jTextFieldAmount.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                if (jTextFieldAmount.getBorder() != emptyTextFieldBorder) {
                    jTextFieldAmount.setBorder(emptyTextFieldBorder);
                }
                calculatePrice();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                if (jTextFieldAmount.getBorder() != emptyTextFieldBorder) {
                    jTextFieldAmount.setBorder(emptyTextFieldBorder);
                }
                calculatePrice();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                if (jTextFieldAmount.getBorder() != emptyTextFieldBorder) {
                    jTextFieldAmount.setBorder(emptyTextFieldBorder);
                }
                calculatePrice();
            }
        });
        jTextFieldWeight.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent e) {
                if (jTextFieldWeight.getBorder() != emptyTextFieldBorder) {
                    jTextFieldWeight.setBorder(emptyTextFieldBorder);
                }
                calculatePrice();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                if (jTextFieldWeight.getBorder() != emptyTextFieldBorder) {
                    jTextFieldWeight.setBorder(emptyTextFieldBorder);
                }
                calculatePrice();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                if (jTextFieldWeight.getBorder() != emptyTextFieldBorder) {
                    jTextFieldWeight.setBorder(emptyTextFieldBorder);
                }
                calculatePrice();
            }
        });

        try {
            establishDBConnection();
        } catch (SQLException ex) {
            errorPopup("Du blev ikke tilsluttet databasen, prøv at ændre indstillingerne.");
            jTabbedPane1.setSelectedIndex(5);
        }
        fillComboDateChoice();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButtonCreateShippingOrder = new javax.swing.JButton();
        jButtonViewShippingOrders = new javax.swing.JButton();
        jButtonConnectToDatabase = new javax.swing.JButton();
        jButtonViewTrucks = new javax.swing.JButton();
        jLabel29 = new javax.swing.JLabel();
        jLabelConnectionSuccess = new javax.swing.JLabel();
        jButtonViewChauffuer = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldClientName = new javax.swing.JTextField();
        jTextFieldClientAddress = new javax.swing.JTextField();
        jTextFieldClientZipCode = new javax.swing.JTextField();
        jTextFieldClientCity = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jComboBoxDate = new javax.swing.JComboBox();
        jComboBoxMonth = new javax.swing.JComboBox();
        jComboBoxYear = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldPickUpName = new javax.swing.JTextField();
        jTextFieldPickUpAddess = new javax.swing.JTextField();
        jTextFieldPickUpZipCode = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldPickUpCity = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jTextFieldDeliveryName = new javax.swing.JTextField();
        jTextFieldDeliveryAddress = new javax.swing.JTextField();
        jTextFieldDeliveryZipCode = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jTextFieldDeliveryCity = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jComboBoxRouteStartCity = new javax.swing.JComboBox();
        jComboBoxRouteStopCity = new javax.swing.JComboBox();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabelAmount = new javax.swing.JLabel();
        jTextFieldAmount = new javax.swing.JTextField();
        jRadioButtonPalletShipping = new javax.swing.JRadioButton();
        jRadioButtonGeneralGoods = new javax.swing.JRadioButton();
        jRadioButtonSpecial = new javax.swing.JRadioButton();
        jLabel27 = new javax.swing.JLabel();
        jTextFieldWeight = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jTextFieldPrice = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaRemarks = new javax.swing.JTextArea();
        jLabel26 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jComboBoxTrucks = new javax.swing.JComboBox();
        jComboBoxDrivers = new javax.swing.JComboBox();
        jTextFieldKM = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jCheckBoxDangerousGoods = new javax.swing.JCheckBox();
        jButtonCreateOrder = new javax.swing.JButton();
        jButtonViewShippingOrders2 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLOrderConfirm = new javax.swing.JLabel();
        jBClearAll = new javax.swing.JButton();
        jLabel37 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jLabelGoodsTypeMissing = new javax.swing.JLabel();
        jLabelDayName = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel31 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTableOverviewShippingOrders2 = new javax.swing.JTable();
        jButtonGetShipments = new javax.swing.JButton();
        jButtonCreateShippingOrder1 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableTrucks = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTableDrivers = new javax.swing.JTable();
        jLabel30 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jTextFieldIPHostname = new javax.swing.JTextField();
        jTextFieldPort = new javax.swing.JTextField();
        jTextFieldDatabaseName = new javax.swing.JTextField();
        jTextFieldUserName = new javax.swing.JTextField();
        jTextFieldPassWord = new javax.swing.JTextField();
        jButtonConnect = new javax.swing.JButton();
        jLabelConnection = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jTabbedPane1.setEnabled(false);
        jTabbedPane1.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Calibri", 1, 36)); // NOI18N
        jLabel1.setText("Næstved Vejtransport");

        jButtonCreateShippingOrder.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonCreateShippingOrder.setText("Opret fragtordre");
        jButtonCreateShippingOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreateShippingOrderActionPerformed(evt);
            }
        });

        jButtonViewShippingOrders.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonViewShippingOrders.setText("Se oversigt over fragtordre");
        jButtonViewShippingOrders.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonViewShippingOrdersActionPerformed(evt);
            }
        });

        jButtonConnectToDatabase.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonConnectToDatabase.setText("Connect til databasen");
        jButtonConnectToDatabase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConnectToDatabaseActionPerformed(evt);
            }
        });

        jButtonViewTrucks.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonViewTrucks.setText("Se oversigt over lastbiler");
        jButtonViewTrucks.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonViewTrucksActionPerformed(evt);
            }
        });

        jLabel29.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel29.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/lastbillogo.png"))); // NOI18N

        jLabelConnectionSuccess.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabelConnectionSuccess.setForeground(new java.awt.Color(0, 0, 255));
        jLabelConnectionSuccess.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jButtonViewChauffuer.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonViewChauffuer.setText("Se oversigt over chauffører");
        jButtonViewChauffuer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonViewChauffuerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(150, 150, 150)
                        .addComponent(jLabel29))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(280, 280, 280)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(150, 150, 150)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonViewShippingOrders, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(jButtonCreateShippingOrder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jButtonViewTrucks, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonConnectToDatabase, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonViewChauffuer, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(287, 287, 287)
                        .addComponent(jLabelConnectionSuccess, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(175, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel29)
                .addGap(6, 6, 6)
                .addComponent(jLabel1)
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCreateShippingOrder)
                    .addComponent(jButtonViewTrucks)
                    .addComponent(jButtonViewChauffuer))
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonViewShippingOrders)
                    .addComponent(jButtonConnectToDatabase))
                .addGap(6, 6, 6)
                .addComponent(jLabelConnectionSuccess, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jTabbedPane1.addTab("Forside", jPanel1);

        jPanel2.setLayout(null);

        jLabel3.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel3.setText("Kunde");
        jPanel2.add(jLabel3);
        jLabel3.setBounds(10, 0, 80, 15);

        jLabel4.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel4.setText("Navn");
        jPanel2.add(jLabel4);
        jLabel4.setBounds(10, 20, 50, 15);

        jLabel5.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel5.setText("Adresse");
        jPanel2.add(jLabel5);
        jLabel5.setBounds(10, 50, 70, 15);

        jLabel6.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel6.setText("Postnr");
        jPanel2.add(jLabel6);
        jLabel6.setBounds(10, 80, 50, 15);

        jLabel7.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel7.setText("By");
        jPanel2.add(jLabel7);
        jLabel7.setBounds(150, 80, 20, 15);

        jTextFieldClientName.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldClientName.setText("Karin Pedersen");
        jTextFieldClientName.setNextFocusableComponent(jTextFieldClientAddress);
        jPanel2.add(jTextFieldClientName);
        jTextFieldClientName.setBounds(80, 20, 180, 30);

        jTextFieldClientAddress.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldClientAddress.setText("Femøvej 3");
        jTextFieldClientAddress.setNextFocusableComponent(jTextFieldClientZipCode);
        jPanel2.add(jTextFieldClientAddress);
        jTextFieldClientAddress.setBounds(80, 50, 180, 30);

        jTextFieldClientZipCode.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldClientZipCode.setText("4700");
        jTextFieldClientZipCode.setNextFocusableComponent(jTextFieldClientCity);
        jPanel2.add(jTextFieldClientZipCode);
        jTextFieldClientZipCode.setBounds(80, 80, 60, 30);

        jTextFieldClientCity.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldClientCity.setText("Næstved");
        jTextFieldClientCity.setNextFocusableComponent(jTextFieldPickUpName);
        jPanel2.add(jTextFieldClientCity);
        jTextFieldClientCity.setBounds(170, 80, 91, 30);

        jLabel8.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel8.setText("Dato");
        jPanel2.add(jLabel8);
        jLabel8.setBounds(10, 140, 70, 15);

        jComboBoxDate.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jComboBoxDate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Dag" }));
        jComboBoxDate.setNextFocusableComponent(jComboBoxMonth);
        jComboBoxDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxDateActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBoxDate);
        jComboBoxDate.setBounds(10, 160, 60, 25);

        jComboBoxMonth.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jComboBoxMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Måned", "Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December" }));
        jComboBoxMonth.setNextFocusableComponent(jComboBoxYear);
        jComboBoxMonth.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxMonthActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBoxMonth);
        jComboBoxMonth.setBounds(80, 160, 90, 25);

        jComboBoxYear.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jComboBoxYear.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "År", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));
        jComboBoxYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxYearActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBoxYear);
        jComboBoxYear.setBounds(180, 160, 60, 25);

        jLabel9.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel9.setText("Afhentningsadresse");
        jPanel2.add(jLabel9);
        jLabel9.setBounds(270, 0, 190, 15);

        jLabel10.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel10.setText("Postnr");
        jPanel2.add(jLabel10);
        jLabel10.setBounds(270, 80, 50, 15);

        jLabel11.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel11.setText("Adresse");
        jPanel2.add(jLabel11);
        jLabel11.setBounds(270, 50, 70, 15);

        jLabel12.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel12.setText("Navn");
        jPanel2.add(jLabel12);
        jLabel12.setBounds(270, 20, 50, 15);

        jTextFieldPickUpName.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldPickUpName.setText("Bilka");
        jTextFieldPickUpName.setNextFocusableComponent(jTextFieldPickUpAddess);
        jPanel2.add(jTextFieldPickUpName);
        jTextFieldPickUpName.setBounds(340, 20, 180, 30);

        jTextFieldPickUpAddess.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldPickUpAddess.setText("Næstved Storcenter 1");
        jTextFieldPickUpAddess.setNextFocusableComponent(jTextFieldPickUpZipCode);
        jPanel2.add(jTextFieldPickUpAddess);
        jTextFieldPickUpAddess.setBounds(340, 50, 180, 30);

        jTextFieldPickUpZipCode.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldPickUpZipCode.setText("4700");
        jTextFieldPickUpZipCode.setNextFocusableComponent(jTextFieldPickUpCity);
        jPanel2.add(jTextFieldPickUpZipCode);
        jTextFieldPickUpZipCode.setBounds(340, 80, 60, 30);

        jLabel13.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel13.setText("By");
        jPanel2.add(jLabel13);
        jLabel13.setBounds(410, 80, 20, 15);

        jTextFieldPickUpCity.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldPickUpCity.setText("Næstved");
        jTextFieldPickUpCity.setNextFocusableComponent(jTextFieldDeliveryName);
        jPanel2.add(jTextFieldPickUpCity);
        jTextFieldPickUpCity.setBounds(430, 80, 91, 30);

        jLabel14.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel14.setText("Leveringsadresse");
        jPanel2.add(jLabel14);
        jLabel14.setBounds(540, 0, 190, 15);

        jLabel15.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel15.setText("Postnr");
        jPanel2.add(jLabel15);
        jLabel15.setBounds(540, 80, 50, 15);

        jLabel16.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel16.setText("Adresse");
        jPanel2.add(jLabel16);
        jLabel16.setBounds(540, 50, 70, 15);

        jLabel17.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel17.setText("Navn");
        jPanel2.add(jLabel17);
        jLabel17.setBounds(540, 20, 50, 15);

        jTextFieldDeliveryName.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldDeliveryName.setText("Geräte Zentrallager");
        jTextFieldDeliveryName.setNextFocusableComponent(jTextFieldDeliveryAddress);
        jPanel2.add(jTextFieldDeliveryName);
        jTextFieldDeliveryName.setBounds(610, 20, 180, 30);

        jTextFieldDeliveryAddress.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldDeliveryAddress.setText("NotkeStrasse 85");
        jTextFieldDeliveryAddress.setNextFocusableComponent(jTextFieldDeliveryZipCode);
        jPanel2.add(jTextFieldDeliveryAddress);
        jTextFieldDeliveryAddress.setBounds(610, 50, 180, 30);

        jTextFieldDeliveryZipCode.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldDeliveryZipCode.setText("22607");
        jTextFieldDeliveryZipCode.setNextFocusableComponent(jTextFieldDeliveryCity);
        jPanel2.add(jTextFieldDeliveryZipCode);
        jTextFieldDeliveryZipCode.setBounds(610, 80, 60, 30);

        jLabel18.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel18.setText("By");
        jPanel2.add(jLabel18);
        jLabel18.setBounds(680, 80, 20, 15);

        jTextFieldDeliveryCity.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldDeliveryCity.setText("Hamburg");
        jTextFieldDeliveryCity.setNextFocusableComponent(jComboBoxDate);
        jPanel2.add(jTextFieldDeliveryCity);
        jTextFieldDeliveryCity.setBounds(700, 80, 91, 30);

        jLabel19.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel19.setText("Rute");
        jPanel2.add(jLabel19);
        jLabel19.setBounds(10, 210, 70, 15);

        jComboBoxRouteStartCity.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jComboBoxRouteStartCity.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Startby" }));
        jComboBoxRouteStartCity.setEnabled(false);
        jComboBoxRouteStartCity.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxRouteStartCityItemStateChanged(evt);
            }
        });
        jPanel2.add(jComboBoxRouteStartCity);
        jComboBoxRouteStartCity.setBounds(10, 230, 100, 25);

        jComboBoxRouteStopCity.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jComboBoxRouteStopCity.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Destination" }));
        jComboBoxRouteStopCity.setEnabled(false);
        jComboBoxRouteStopCity.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxRouteStopCityItemStateChanged(evt);
            }
        });
        jPanel2.add(jComboBoxRouteStopCity);
        jComboBoxRouteStopCity.setBounds(120, 230, 120, 25);

        jLabel20.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel20.setText("Afstand");
        jPanel2.add(jLabel20);
        jLabel20.setBounds(440, 310, 70, 15);

        jLabel21.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel21.setText("Fragttype");
        jPanel2.add(jLabel21);
        jLabel21.setBounds(10, 260, 120, 15);

        jLabelAmount.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabelAmount.setText("M³/Paller");
        jPanel2.add(jLabelAmount);
        jLabelAmount.setBounds(180, 260, 90, 15);

        jTextFieldAmount.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldAmount.setDocument(new NumberRestrictionDocument(2));
        jTextFieldAmount.setText("17");
        jPanel2.add(jTextFieldAmount);
        jTextFieldAmount.setBounds(180, 280, 55, 30);

        buttonGroup1.add(jRadioButtonPalletShipping);
        jRadioButtonPalletShipping.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jRadioButtonPalletShipping.setText("Pallefragt");
        jRadioButtonPalletShipping.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonPalletShippingActionPerformed(evt);
            }
        });
        jPanel2.add(jRadioButtonPalletShipping);
        jRadioButtonPalletShipping.setBounds(10, 280, 150, 24);

        buttonGroup1.add(jRadioButtonGeneralGoods);
        jRadioButtonGeneralGoods.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jRadioButtonGeneralGoods.setText("Stykgods");
        jRadioButtonGeneralGoods.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonGeneralGoodsActionPerformed(evt);
            }
        });
        jPanel2.add(jRadioButtonGeneralGoods);
        jRadioButtonGeneralGoods.setBounds(10, 300, 100, 24);

        buttonGroup1.add(jRadioButtonSpecial);
        jRadioButtonSpecial.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jRadioButtonSpecial.setText("Special");
        jRadioButtonSpecial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonSpecialActionPerformed(evt);
            }
        });
        jPanel2.add(jRadioButtonSpecial);
        jRadioButtonSpecial.setBounds(10, 320, 100, 24);

        jLabel27.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel27.setText("Vægt");
        jPanel2.add(jLabel27);
        jLabel27.setBounds(180, 310, 70, 15);

        jTextFieldWeight.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldWeight.setDocument(new NumberRestrictionDocument(5));
        jTextFieldWeight.setText("1000");
        jPanel2.add(jTextFieldWeight);
        jTextFieldWeight.setBounds(180, 330, 55, 30);

        jLabel23.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel23.setText("Pris");
        jPanel2.add(jLabel23);
        jLabel23.setBounds(300, 310, 40, 15);

        jTextFieldPrice.setEditable(false);
        jTextFieldPrice.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldPrice.setText("0");
        jTextFieldPrice.setFocusable(false);
        jPanel2.add(jTextFieldPrice);
        jTextFieldPrice.setBounds(350, 310, 59, 30);

        jLabel24.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel24.setText("Bemærkninger");
        jPanel2.add(jLabel24);
        jLabel24.setBounds(10, 350, 130, 15);

        jTextAreaRemarks.setColumns(20);
        jTextAreaRemarks.setRows(5);
        jTextAreaRemarks.setText("Massere af kattemad");
        jScrollPane1.setViewportView(jTextAreaRemarks);

        jPanel2.add(jScrollPane1);
        jScrollPane1.setBounds(10, 370, 570, 87);

        jLabel26.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel26.setText("Køretøj");
        jPanel2.add(jLabel26);
        jLabel26.setBounds(10, 470, 90, 15);

        jLabel28.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel28.setText("Chauffør");
        jPanel2.add(jLabel28);
        jLabel28.setBounds(370, 470, 120, 15);

        jComboBoxTrucks.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jComboBoxTrucks.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxTrucksActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBoxTrucks);
        jComboBoxTrucks.setBounds(10, 490, 212, 25);

        jComboBoxDrivers.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jComboBoxDrivers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxDriversActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBoxDrivers);
        jComboBoxDrivers.setBounds(370, 490, 212, 25);

        jTextFieldKM.setEditable(false);
        jTextFieldKM.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldKM.setText("0");
        jTextFieldKM.setFocusable(false);
        jPanel2.add(jTextFieldKM);
        jTextFieldKM.setBounds(520, 310, 59, 30);

        jLabel22.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel22.setText("Farligt gods");
        jPanel2.add(jLabel22);
        jLabel22.setBounds(300, 260, 100, 15);

        jCheckBoxDangerousGoods.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jCheckBoxDangerousGoods.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxDangerousGoodsActionPerformed(evt);
            }
        });
        jPanel2.add(jCheckBoxDangerousGoods);
        jCheckBoxDangerousGoods.setBounds(400, 256, 20, 24);

        jButtonCreateOrder.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonCreateOrder.setText("Opret Ordre");
        jButtonCreateOrder.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButtonCreateOrderMouseExited(evt);
            }
        });
        jButtonCreateOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreateOrderActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonCreateOrder);
        jButtonCreateOrder.setBounds(610, 450, 110, 27);

        jButtonViewShippingOrders2.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonViewShippingOrders2.setText("Se oversigt over fragtordre");
        jButtonViewShippingOrders2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonViewShippingOrders2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonViewShippingOrders2);
        jButtonViewShippingOrders2.setBounds(610, 490, 230, 27);

        jButton2.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/home-icon.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2);
        jButton2.setBounds(860, 10, 50, 40);

        jLOrderConfirm.setFont(new java.awt.Font("Calibri", 1, 15)); // NOI18N
        jLOrderConfirm.setForeground(java.awt.Color.blue);
        jLOrderConfirm.setText("Ordre oprettet.");
        jPanel2.add(jLOrderConfirm);
        jLOrderConfirm.setBounds(610, 410, 150, 18);

        jBClearAll.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jBClearAll.setText("Ryd alle felter");
        jBClearAll.setMaximumSize(new java.awt.Dimension(95, 25));
        jBClearAll.setMinimumSize(new java.awt.Dimension(95, 25));
        jBClearAll.setPreferredSize(new java.awt.Dimension(95, 25));
        jBClearAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBClearAllActionPerformed(evt);
            }
        });
        jPanel2.add(jBClearAll);
        jBClearAll.setBounds(730, 450, 110, 25);

        jLabel37.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel37.setText("Km");
        jPanel2.add(jLabel37);
        jLabel37.setBounds(600, 310, 40, 15);

        jCheckBox1.setText("Samme adresse som kunde");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });
        jPanel2.add(jCheckBox1);
        jCheckBox1.setBounds(270, 120, 230, 24);

        jCheckBox2.setText("Samme adresse som kunde");
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });
        jPanel2.add(jCheckBox2);
        jCheckBox2.setBounds(540, 120, 250, 24);

        jLabelGoodsTypeMissing.setFont(new java.awt.Font("SansSerif", 1, 48)); // NOI18N
        jLabelGoodsTypeMissing.setForeground(new java.awt.Color(255, 0, 0));
        jLabelGoodsTypeMissing.setVisible(false);
        jLabelGoodsTypeMissing.setText("!");
        jPanel2.add(jLabelGoodsTypeMissing);
        jLabelGoodsTypeMissing.setBounds(100, 280, 30, 60);

        jLabelDayName.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jPanel2.add(jLabelDayName);
        jLabelDayName.setBounds(250, 163, 310, 20);

        jTabbedPane1.addTab("Opret Ordre", jPanel2);

        jPanel4.setLayout(null);

        jLabel31.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel31.setText("Oversigt over fragtordrer");
        jPanel4.add(jLabel31);
        jLabel31.setBounds(10, 40, 220, 15);

        jTableOverviewShippingOrders2.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTableOverviewShippingOrders2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Fornavn", "Efternavn", "Startby", "Slutby", "Km", "Godstype", "Godspris", "Dag", "Dato", "Uge"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(jTableOverviewShippingOrders2);

        jPanel4.add(jScrollPane4);
        jScrollPane4.setBounds(10, 60, 900, 450);

        jButtonGetShipments.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonGetShipments.setText("Opdater");
        jButtonGetShipments.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGetShipmentsActionPerformed(evt);
            }
        });
        jPanel4.add(jButtonGetShipments);
        jButtonGetShipments.setBounds(765, 0, 80, 27);

        jButtonCreateShippingOrder1.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonCreateShippingOrder1.setText("Opret fragtordre");
        jButtonCreateShippingOrder1.setInheritsPopupMenu(true);
        jButtonCreateShippingOrder1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreateShippingOrder1ActionPerformed(evt);
            }
        });
        jPanel4.add(jButtonCreateShippingOrder1);
        jButtonCreateShippingOrder1.setBounds(715, 30, 130, 27);

        jButton4.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/home-icon.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel4.add(jButton4);
        jButton4.setBounds(860, 10, 50, 40);

        jTabbedPane1.addTab("Oversigt over Fragtordrer", jPanel4);

        jPanel3.setLayout(null);

        jLabel2.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel2.setText("Lastbiler");
        jPanel3.add(jLabel2);
        jLabel2.setBounds(10, 40, 120, 15);

        jTableTrucks.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTableTrucks.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Type", "Pallekapacitet", "Volumen", "Max Vægt", "Specialfragt"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableTrucks.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane2.setViewportView(jTableTrucks);
        if (jTableTrucks.getColumnModel().getColumnCount() > 0) {
            jTableTrucks.getColumnModel().getColumn(0).setMinWidth(160);
        }

        jPanel3.add(jScrollPane2);
        jScrollPane2.setBounds(10, 60, 900, 450);

        jButton3.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/home-icon.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton3);
        jButton3.setBounds(860, 10, 50, 40);

        jTabbedPane1.addTab("Oversigt over Lastbiler", jPanel3);

        jPanel6.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jPanel6.setLayout(null);

        jTableDrivers.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTableDrivers.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Fornavn", "Efternavn", "Certifikator"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(jTableDrivers);

        jPanel6.add(jScrollPane3);
        jScrollPane3.setBounds(10, 60, 900, 450);

        jLabel30.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel30.setText("Chauffører");
        jPanel6.add(jLabel30);
        jLabel30.setBounds(10, 40, 150, 15);

        jButton5.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/home-icon.png"))); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel6.add(jButton5);
        jButton5.setBounds(860, 10, 50, 40);

        jTabbedPane1.addTab("Oversigt over Chauffører", jPanel6);

        jPanel5.setLayout(null);

        jLabel32.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel32.setText("IP/Hostname");
        jPanel5.add(jLabel32);
        jLabel32.setBounds(10, 0, 100, 15);

        jLabel33.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel33.setText("Port");
        jPanel5.add(jLabel33);
        jLabel33.setBounds(10, 30, 60, 15);

        jLabel34.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel34.setText("Databasenavn");
        jPanel5.add(jLabel34);
        jLabel34.setBounds(10, 60, 103, 15);

        jLabel35.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel35.setText("Brugernavn");
        jPanel5.add(jLabel35);
        jLabel35.setBounds(10, 90, 82, 15);

        jLabel36.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jLabel36.setText("Password");
        jPanel5.add(jLabel36);
        jLabel36.setBounds(10, 120, 70, 15);

        jTextFieldIPHostname.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldIPHostname.setText("localhost");
        jPanel5.add(jTextFieldIPHostname);
        jTextFieldIPHostname.setBounds(120, 0, 159, 30);

        jTextFieldPort.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldPort.setText("3306");
        jPanel5.add(jTextFieldPort);
        jTextFieldPort.setBounds(120, 30, 159, 30);

        jTextFieldDatabaseName.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldDatabaseName.setText("transport");
        jPanel5.add(jTextFieldDatabaseName);
        jTextFieldDatabaseName.setBounds(120, 60, 159, 30);

        jTextFieldUserName.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldUserName.setText("root");
        jPanel5.add(jTextFieldUserName);
        jTextFieldUserName.setBounds(120, 90, 159, 30);

        jTextFieldPassWord.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jTextFieldPassWord.setText("root");
        jTextFieldPassWord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldPassWordActionPerformed(evt);
            }
        });
        jPanel5.add(jTextFieldPassWord);
        jTextFieldPassWord.setBounds(120, 120, 159, 30);

        jButtonConnect.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButtonConnect.setText("Connect");
        jButtonConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConnectActionPerformed(evt);
            }
        });
        jPanel5.add(jButtonConnect);
        jButtonConnect.setBounds(120, 150, 100, 27);

        jLabelConnection.setForeground(new java.awt.Color(2, 66, 249));
        jPanel5.add(jLabelConnection);
        jLabelConnection.setBounds(50, 190, 540, 50);

        jButton6.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/home-icon.png"))); // NOI18N
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel5.add(jButton6);
        jButton6.setBounds(860, 10, 50, 40);

        jTabbedPane1.addTab("Connect til Databasen", jPanel5);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 929, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 550, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @SuppressWarnings("unchecked")
    private void fillComboDateChoice() {
        for (ActionListener actionListener : jComboBoxDate.getActionListeners()) {
            jComboBoxDate.removeActionListener(actionListener);
        }
        int index = jComboBoxDate.getSelectedIndex();
        int month = (jComboBoxMonth.getSelectedIndex() == 0)
                ? 1 : jComboBoxMonth.getSelectedIndex();
        int year
                = (jComboBoxYear.getSelectedIndex() == 0)
                ? 2013 : Integer.parseInt(jComboBoxYear.getSelectedItem().toString());
        int maxDays = DateUtil.maxDays(month, year);
        jComboBoxDate.removeAllItems();
        jComboBoxDate.addItem("Dag");
        for (int i = 1; i <= maxDays; i++) {
            jComboBoxDate.addItem(i);
        }
        if (index > jComboBoxDate.getItemCount() - 1) {
            index = jComboBoxDate.getItemCount() - 1;
        }
        if (index > 0) {
            jComboBoxDate.setSelectedIndex(index);
        }
        jComboBoxDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxDateActionPerformed(evt);
            }
        });
    }

    private void establishDBConnection() throws SQLException {
        String hostIP = jTextFieldIPHostname.getText();
        String port = jTextFieldPort.getText();
        String user = jTextFieldUserName.getText();
        String password = jTextFieldPassWord.getText();
        String db = jTextFieldDatabaseName.getText();
        try {
            databasse = new DatabaseConnection(hostIP, port, db, user, password);
            jLabelConnection.setText("Du er nu forbundet til databasen.");
            jLabelConnectionSuccess.setText("Du er forbundet til databasen.");
            jTabbedPane1.setEnabled(true);
            jTabbedPane1.setSelectedIndex(0);
            getShipments();
            getTruckOverview();
            getDriverOverView();
        } catch (ClassNotFoundException ex) {
            errorPopup("Database driveren er ikke installeret korrekt. Kontakt support.");
        }
    }

    @SuppressWarnings("unchecked")
    private void fillComboCity() {
        for (ItemListener itemListener : jComboBoxRouteStartCity.getItemListeners()) {
            jComboBoxRouteStartCity.removeItemListener(itemListener);
        }
        if (databasse != null) {
            try {
                CityHandler ch = new CityHandler(databasse);
                ArrayList<City> list = ch.getCities();
                City startCity = null;
                if (jComboBoxRouteStartCity.getSelectedIndex() > 0) {
                    startCity = (City) jComboBoxRouteStartCity.getSelectedItem();
                }
                jComboBoxRouteStartCity.removeAllItems();
                jComboBoxRouteStartCity.addItem("Startby");
                int year = 2013;
                if (jComboBoxYear.getSelectedIndex() > 0) {
                    year = Integer.parseInt(jComboBoxYear.getSelectedItem().toString());
                }
                int month = jComboBoxMonth.getSelectedIndex();
                int day = jComboBoxDate.getSelectedIndex();

                for (City city : list) {
                    if (jComboBoxYear.getSelectedIndex() == 0 && jComboBoxMonth.getSelectedIndex() == 0 && jComboBoxDate.getSelectedIndex() == 0) {
                        jComboBoxRouteStartCity.addItem(city);
                    } else if (DateUtil.getDayOfTheWeek(year, month, day) != 1
                            || (!city.getCountry().equals("Tyskland")
                            && !city.getCountry().equals("Belgien")
                            && !city.getCountry().equals("Holland"))) {
                        jComboBoxRouteStartCity.addItem(city);
                    }
                    if (city.equals(startCity)) {
                        jComboBoxRouteStartCity.setSelectedItem(city);
                    } else {
                        if (jComboBoxRouteStartCity.getSelectedIndex() == 0 || jComboBoxRouteStopCity.getSelectedIndex() == 0) {
                            jTextFieldKM.setText("0");
                        }
                    }
                }
            } catch (SQLException ex) {
                errorPopup("Kunne ikke hente byer fra databasen. Kontakt support.");
            }
            jComboBoxRouteStartCity.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    jComboBoxRouteStartCityItemStateChanged(evt);
                }
            });
        }
    }

    @SuppressWarnings("unchecked")
    private void fillComboEndCity() {
        for (ItemListener itemListener : jComboBoxRouteStopCity.getItemListeners()) {
            jComboBoxRouteStopCity.removeItemListener(itemListener);
        }
        if (databasse != null) {
            try {
                CityHandler ch = new CityHandler(databasse);
                City endCity = null;
                if (jComboBoxRouteStopCity.getSelectedIndex() > 0) {
                    endCity = (City) jComboBoxRouteStopCity.getSelectedItem();
                }
                City startCity;
                ArrayList<City> list;
                if (jComboBoxRouteStartCity.getSelectedIndex() > 0) {
                    startCity = (City) jComboBoxRouteStartCity.getSelectedItem();
                    list = ch.getValidCities(startCity);
                } else {
                    list = ch.getCities();
                }
                jComboBoxRouteStopCity.removeAllItems();
                jComboBoxRouteStopCity.addItem("Destination");
                int year = 2013;
                if (jComboBoxYear.getSelectedIndex() > 0) {
                    year = Integer.parseInt(jComboBoxYear.getSelectedItem().toString());
                }
                int month = jComboBoxMonth.getSelectedIndex();
                int day = jComboBoxDate.getSelectedIndex();
                for (City city : list) {
                    if (jComboBoxYear.getSelectedIndex() == 0 && jComboBoxMonth.getSelectedIndex() == 0 && jComboBoxDate.getSelectedIndex() == 0) {
                        jComboBoxRouteStopCity.addItem(city);
                    } else if (DateUtil.getDayOfTheWeek(year, month, day) != 1
                            || (!city.getCountry().equals("Tyskland")
                            && !city.getCountry().equals("Belgien")
                            && !city.getCountry().equals("Holland"))) {
                        jComboBoxRouteStopCity.addItem(city);
                    }
                    if (city.equals(endCity)) {
                        jComboBoxRouteStopCity.setSelectedItem(city);
                    } else {
                        if (jComboBoxRouteStartCity.getSelectedIndex() == 0 || jComboBoxRouteStopCity.getSelectedIndex() == 0) {
                            jTextFieldKM.setText("0");
                        }
                    }
                }
            } catch (SQLException ex) {
                errorPopup("Kunne ikke hente byer fra databasen. Kontakt support.");
            }
            jComboBoxRouteStopCity.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    jComboBoxRouteStopCityItemStateChanged(evt);
                }
            });
        }
    }

    @SuppressWarnings("unchecked")
    private void fillComboDriver() {
        if (databasse != null) {
            for (ActionListener actionListener : jComboBoxDrivers.getActionListeners()) {
                jComboBoxDrivers.removeActionListener(actionListener);
            }
            if (jComboBoxRouteStartCity.getSelectedIndex() > 0 && jComboBoxRouteStopCity.getSelectedIndex() > 0) {
                try {
                    Driver currentDriver = null;
                    if (jComboBoxDrivers.getSelectedItem() != null) {
                        currentDriver = (Driver) jComboBoxDrivers.getSelectedItem();
                    }
                    jComboBoxDrivers.removeAllItems();
                    DriverHandler dh = new DriverHandler(databasse);
                    String date;
                    if (jComboBoxYear.getSelectedIndex() > 0 && jComboBoxMonth.getSelectedIndex() > 0 && jComboBoxDate.getSelectedIndex() > 0) {
                        date = jComboBoxYear.getSelectedItem().toString() + "-" + jComboBoxMonth.getSelectedIndex() + "-" + jComboBoxDate.getSelectedItem().toString();
                    } else {
                        date = DateUtil.currentDate();
                    }
                    boolean dg = jCheckBoxDangerousGoods.isSelected();
                    boolean special = false;
                    if (getSelectedGoodsType() == 3) {
                        special = true;
                    }
                    City originCity = (City) jComboBoxRouteStartCity.getSelectedItem();
                    City destination = (City) jComboBoxRouteStopCity.getSelectedItem();
                    boolean eu = false;
                    String[] euCountry = {"Tyskland", "Belgien", "Holland"};
                    for (String string : euCountry) {
                        if (string.equals(originCity.getCountry()) || string.equals(destination.getCountry())) {
                            eu = true;
                        }
                    }
                    ArrayList<Driver> list = dh.getValidDrivers(date, dg, special, eu);
                    for (Driver driver : list) {
                        jComboBoxDrivers.addItem(driver);
                        if (driver.equals(currentDriver)) {
                            jComboBoxDrivers.setSelectedItem(driver);
                        }
                    }
                } catch (SQLException ex) {
                    errorPopup("Kunne ikke hente chauffører fra databasen. Kontakt support.");
                }
                jComboBoxDrivers.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jComboBoxDriversActionPerformed(evt);
                    }
                });
            }
        }
    }

    @SuppressWarnings("unchecked")
    private void fillComboTruck() {
        if (databasse != null) {
            for (ActionListener actionListener : jComboBoxTrucks.getActionListeners()) {
                jComboBoxTrucks.removeActionListener(actionListener);
            }
            try {
                Truck currentTruck = null;
                if (jComboBoxDrivers.getSelectedItem() != null) {
                    currentTruck = (Truck) jComboBoxTrucks.getSelectedItem();
                }
                jComboBoxTrucks.removeAllItems();
                TruckHandler th = new TruckHandler(databasse);
                String date;
                if (jComboBoxYear.getSelectedIndex() > 0 && jComboBoxMonth.getSelectedIndex() > 0 && jComboBoxDate.getSelectedIndex() > 0) {
                    date = jComboBoxYear.getSelectedItem().toString() + "-" + jComboBoxMonth.getSelectedIndex() + "-" + jComboBoxDate.getSelectedItem().toString();
                } else {
                    date = DateUtil.currentDate();
                }
                int weight = Integer.parseInt(jTextFieldWeight.getText());
                int volume = 0;
                int pallet = 0;
                boolean special = false;
                if (getSelectedGoodsType() == 1) {
                    pallet = Integer.parseInt(jTextFieldAmount.getText());
                } else if (getSelectedGoodsType() == 2) {
                    volume = Integer.parseInt(jTextFieldAmount.getText());
                } else {
                    special = true;
                    volume = Integer.parseInt(jTextFieldAmount.getText());
                }
                ArrayList<Truck> list = th.getValidTrucks(date, weight, volume, pallet, special);
                for (Truck truck : list) {
                    jComboBoxTrucks.addItem(truck);
                    if (truck.equals(currentTruck)) {
                        jComboBoxTrucks.setSelectedItem(truck);
                    }
                }
            } catch (SQLException ex) {
                errorPopup("Kunne ikke hente lastbiler fra databasen. Kontakt support.");
            }
            jComboBoxTrucks.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jComboBoxTrucksActionPerformed(evt);
                }
            });
        }
    }

    private boolean isInteger(String str) {
        try {
            Integer.parseInt(str);
            return true;
        } catch (NumberFormatException ex) {
            return false;
        }
    }

    private void calculatePrice() {
        if (getSelectedGoodsType() != 0 && isInteger(jTextFieldAmount.getText())
                && isInteger(jTextFieldWeight.getText()) && route != null
                && jComboBoxYear.getSelectedIndex() > 0 && jComboBoxMonth.getSelectedIndex() > 0
                && jComboBoxDate.getSelectedIndex() > 0) {
            try {
                int type = getSelectedGoodsType();
                int amount = Integer.parseInt(jTextFieldAmount.getText());
                int weight = Integer.parseInt(jTextFieldWeight.getText());
                boolean dg = jCheckBoxDangerousGoods.isSelected();
                GoodsPriceHandler gph = new GoodsPriceHandler(databasse);
                int price = gph.getPriceByRoute(route, dg, amount, weight, type);
                jTextFieldPrice.setText(price + "");
                fillComboTruck();
                fillComboDriver();
            } catch (SQLException ex) {
                errorPopup("Kunne ikke finde prisen i databasen. Kontakt support.");
            } catch (Exception ex) {
                if (ex.getMessage().equals("Vejer for meget.")) {
                    jTextFieldWeight.setBorder(redLineBorder);
                } else {
                    jTextFieldAmount.setBorder(redLineBorder);
                }
                errorPopup(ex.getMessage());
            }
        }

    }

    private int getSelectedGoodsType() {
        int type = 0;
        if (jRadioButtonPalletShipping.isSelected()) {
            type = 1;
            jLabelAmount.setText("Paller");
        } else if (jRadioButtonGeneralGoods.isSelected()) {
            type = 2;
            jLabelAmount.setText("M³");
        } else if (jRadioButtonSpecial.isSelected()) {
            type = 3;
            jLabelAmount.setText("M³");
        }

        return type;
    }

    private void getRoute(ItemEvent evt) {
        if (jComboBoxRouteStartCity.getSelectedItem() != null
                && jComboBoxRouteStopCity.getSelectedItem() != null
                && jComboBoxRouteStartCity.getSelectedIndex() > 0
                && jComboBoxRouteStopCity.getSelectedIndex() > 0
                && evt.getStateChange() == ItemEvent.SELECTED) {
            jComboBoxRouteStopCity.setBorder(emptyComboBoxBorder);
            jComboBoxRouteStartCity.setBorder(emptyComboBoxBorder);
            try {
                City c1 = (City) jComboBoxRouteStartCity.getSelectedItem();
                City c2 = (City) jComboBoxRouteStopCity.getSelectedItem();
                RouteHandler rh = new RouteHandler(databasse);
                route = rh.getRoute(c1, c2);
                if (route != null) {
                    jTextFieldKM.setText("" + route.getKm());
                }
                calculatePrice();
            } catch (SQLException ex) {
                errorPopup("Kunne ikke finde ruten i databasen.Kontakt support.");
            }
        }
    }

    private void showEmpty() {
        if (jComboBoxDate.getSelectedIndex() == 0) {
            jComboBoxDate.setBorder(redLineBorder);
        } else {
            jComboBoxDate.setBorder(emptyComboBoxBorder);
        }
        if (jComboBoxMonth.getSelectedIndex() == 0) {
            jComboBoxMonth.setBorder(redLineBorder);
        } else {
            jComboBoxMonth.setBorder(emptyComboBoxBorder);
        }
        if (jComboBoxYear.getSelectedIndex() == 0) {
            jComboBoxYear.setBorder(redLineBorder);
        } else {
            jComboBoxYear.setBorder(emptyComboBoxBorder);
        }
        if (jComboBoxRouteStartCity.getSelectedIndex() == 0) {
            jComboBoxRouteStartCity.setBorder(redLineBorder);
        } else {
            jComboBoxRouteStartCity.setBorder(emptyComboBoxBorder);
        }
        if (jComboBoxRouteStopCity.getSelectedIndex() == 0) {
            jComboBoxRouteStopCity.setBorder(redLineBorder);
        } else {
            jComboBoxRouteStopCity.setBorder(emptyComboBoxBorder);
        }
        if (jComboBoxDrivers.getSelectedItem() == null) {
            jComboBoxDrivers.setBorder(redLineBorder);
        } else {
            jComboBoxDrivers.setBorder(emptyComboBoxBorder);
        }
        if (jComboBoxTrucks.getSelectedItem() == null) {
            jComboBoxTrucks.setBorder(redLineBorder);
        } else {
            jComboBoxTrucks.setBorder(emptyComboBoxBorder);
        }
        if (jTextFieldAmount.getText().isEmpty() || jTextFieldAmount.getText().substring(0, 1).equals("0")) {
            jTextFieldAmount.setBorder(redLineBorder);
        } else {
            jTextFieldAmount.setBorder(emptyTextFieldBorder);
        }
        if (jTextFieldWeight.getText().isEmpty() || jTextFieldWeight.getText().substring(0, 1).equals("0")) {
            jTextFieldWeight.setBorder(redLineBorder);
        } else {
            jTextFieldWeight.setBorder(emptyTextFieldBorder);
        }
        if (getSelectedGoodsType() == 0) {
            jLabelGoodsTypeMissing.setVisible(true);
        } else {
            jLabelGoodsTypeMissing.setVisible(false);
        }
    }

    private boolean checkForEmpty() {
        //Eksempel på hvordan man kunne lave brugervenlighed ved at vise hvilke felter som ikke er udfyldte            
        showEmpty();
        return jComboBoxYear.getSelectedIndex() > 0 && jComboBoxMonth.getSelectedIndex() > 0
                && jComboBoxDate.getSelectedIndex() > 0 && !jTextFieldAmount.getText().isEmpty()
                && !jTextFieldWeight.getText().isEmpty() && !jTextFieldPrice.getText().isEmpty()
                && !jTextFieldClientName.getText().isEmpty() && !jTextFieldClientAddress.getText().isEmpty()
                && !jTextFieldClientZipCode.getText().isEmpty() && !jTextFieldClientCity.getText().isEmpty()
                && !jTextFieldPickUpName.getText().isEmpty() && !jTextFieldPickUpAddess.getText().isEmpty()
                && !jTextFieldPickUpZipCode.getText().isEmpty() && !jTextFieldPickUpCity.getText().isEmpty()
                && !jTextFieldDeliveryName.getText().isEmpty() && !jTextFieldDeliveryAddress.getText().isEmpty()
                && !jTextFieldDeliveryZipCode.getText().isEmpty() && !jTextFieldDeliveryCity.getText().isEmpty()
                && jComboBoxRouteStartCity.getSelectedIndex() > 0 && jComboBoxRouteStopCity.getSelectedIndex() > 0
                && jComboBoxTrucks.getSelectedItem() != null && jComboBoxDrivers.getSelectedItem() != null
                && !jTextFieldKM.getText().equals("0") && !jTextFieldPrice.getText().equals("0")
                && !jTextFieldAmount.getText().substring(0, 1).equals("0") && !jTextFieldWeight.getText().substring(0, 1).equals("0")
                && getSelectedGoodsType() != 0;
    }

    @SuppressWarnings("unchecked")
    private void getShipments() {
        ShipmentHandler sh = new ShipmentHandler(databasse);
        if (databasse != null) {
            try {
                ArrayList<String[]> shipmentList = sh.getShipmentOverview();
                DefaultTableModel shipmentModel = (DefaultTableModel) jTableOverviewShippingOrders2.getModel();
                shipmentModel.setRowCount(0);
                jTableOverviewShippingOrders2.setRowSorter(new TableRowSorter(shipmentModel));
                for (String[] shipment : shipmentList) {
                    shipmentModel.addRow(new Object[]{shipment[0], shipment[1], shipment[2], shipment[3], shipment[4], shipment[5], shipment[6], shipment[7], shipment[8], shipment[9]});
                }
            } catch (SQLException ex) {
                errorPopup("Kan ikke hente fragtordrer fra databasen. Kontakt support.");
            }
        }
    }

    @SuppressWarnings("unchecked")
    private void getTruckOverview() {
        TruckHandler th = new TruckHandler(databasse);
        if (databasse != null) {
            try {
                ArrayList<Truck> trucklist = th.getTrucks();
                DefaultTableModel trucksModel = (DefaultTableModel) jTableTrucks.getModel();
                trucksModel.setRowCount(0);
                jTableTrucks.setRowSorter(new TableRowSorter(trucksModel));
                for (Truck truck : trucklist) {
                    trucksModel.addRow(new Object[]{truck.getTruckType(), truck.getPalletCapacity() + " styk", truck.getVolume() + " m³", truck.getMaxWeight() + " kg", truck.getStrSpecialShipment()});
                }
            } catch (SQLException ex) {
                errorPopup("Kan ikke hente lastbiler fra databasen. Kontakt support.");
            }
        }
    }

    @SuppressWarnings("unchecked")
    private void getDriverOverView() {
        DriverHandler dh = new DriverHandler(databasse);
        if (databasse != null) {
            try {
                ArrayList<String[]> driverlist = dh.getDrivers();
                DefaultTableModel driversModel = (DefaultTableModel) jTableDrivers.getModel();
                driversModel.setRowCount(0);
                jTableDrivers.setRowSorter(new TableRowSorter(driversModel));
                for (String[] driver : driverlist) {
                    driversModel.addRow(new Object[]{driver[0], driver[1], driver[2]});
                }
            } catch (SQLException ex) {
                errorPopup("Kan ikke hente chauffører fra databasen. Kontakt support.");
            }
        }
    }

    private void errorPopup(String str) {
        JOptionPane.showMessageDialog(null, str);
    }

    private void dateCheck() {
        if (jComboBoxDate.getSelectedIndex() > 0 && jComboBoxMonth.getSelectedIndex() > 0 && jComboBoxYear.getSelectedIndex() > 0) {
            jComboBoxRouteStartCity.setEnabled(true);
            jComboBoxRouteStopCity.setEnabled(true);
            int day = jComboBoxDate.getSelectedIndex();
            int month = (jComboBoxMonth.getSelectedIndex() == 0)
                    ? 1 : jComboBoxMonth.getSelectedIndex();
            int year
                    = (jComboBoxYear.getSelectedIndex() == 0)
                    ? 2013 : Integer.parseInt(jComboBoxYear.getSelectedItem().toString());
            String dayName = DateUtil.getDayNameFromCal(year, month, day);
            if (dayName.equals("Søndag")) {
                dayName = dayName + " (EU byer er undladt)";
            }
            jLabelDayName.setText(dayName);
        } else {
            jComboBoxRouteStartCity.setEnabled(false);
            jComboBoxRouteStopCity.setEnabled(false);
            jLabelDayName.setText("");
        }
    }
    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if (databasse != null) {
            try {
                databasse.close();
            } catch (SQLException ex) {
                errorPopup("Fejl i kommunikation med databasen, mens der prøves at lukke for forbindelse.");
            }
        }
    }//GEN-LAST:event_formWindowClosing

    private void jButtonConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConnectActionPerformed
        try {
            establishDBConnection();
        } catch (SQLException ex) {
            errorPopup("Fejl i kommunikation med databasen. Prøv at tjekke brugernavn og password.");
        }
    }//GEN-LAST:event_jButtonConnectActionPerformed

    private void jTextFieldPassWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldPassWordActionPerformed
        try {
            establishDBConnection();
        } catch (SQLException ex) {
            errorPopup("Fejl i kommunikation med databasen. Prøv at tjekke brugernavn og password.");
        }
    }//GEN-LAST:event_jTextFieldPassWordActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        jTabbedPane1.setSelectedIndex(0);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButtonCreateShippingOrder1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreateShippingOrder1ActionPerformed
        jTabbedPane1.setSelectedIndex(1);
    }//GEN-LAST:event_jButtonCreateShippingOrder1ActionPerformed

    private void jButtonGetShipmentsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGetShipmentsActionPerformed
        getShipments();
    }//GEN-LAST:event_jButtonGetShipmentsActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        jTabbedPane1.setSelectedIndex(0);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jBClearAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBClearAllActionPerformed
        jTextAreaRemarks.setText("");
        jTextFieldAmount.setText("");
        jTextFieldClientAddress.setText("");
        jTextFieldClientCity.setText("");
        jTextFieldClientName.setText("");
        jTextFieldClientZipCode.setText("");
        jTextFieldDatabaseName.setText("");
        jTextFieldDeliveryAddress.setText("");
        jTextFieldDeliveryCity.setText("");
        jTextFieldDeliveryName.setText("");
        jTextFieldDeliveryZipCode.setText("");
        jTextFieldKM.setText("");
        jTextFieldPickUpAddess.setText("");
        jTextFieldPickUpCity.setText("");
        jTextFieldPickUpName.setText("");
        jTextFieldPickUpZipCode.setText("");
        jTextFieldPrice.setText("");
        jTextFieldWeight.setText("");
        jComboBoxRouteStartCity.setSelectedIndex(0);
        jComboBoxRouteStopCity.setSelectedIndex(0);
    }//GEN-LAST:event_jBClearAllActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        jTabbedPane1.setSelectedIndex(0);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButtonViewShippingOrders2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonViewShippingOrders2ActionPerformed
        jTabbedPane1.setSelectedIndex(2);
        getShipments();
    }//GEN-LAST:event_jButtonViewShippingOrders2ActionPerformed

    private void jButtonCreateOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreateOrderActionPerformed
        if (checkForEmpty()) {
            try {
                String date = jComboBoxYear.getSelectedItem().toString() + "-" + jComboBoxMonth.getSelectedIndex() + "-" + jComboBoxDate.getSelectedItem().toString();
                boolean dangerousGoods = jCheckBoxDangerousGoods.isSelected();
                int goodsType = getSelectedGoodsType();
                int amount = Integer.parseInt(jTextFieldAmount.getText());
                int weight = Integer.parseInt(jTextFieldWeight.getText());
                String comment = jTextAreaRemarks.getText();
                String customer = jTextFieldClientName.getText() + "\n" + jTextFieldClientAddress.getText() + "\n" + jTextFieldClientZipCode.getText() + " " + jTextFieldClientCity.getText();
                String startAddress = jTextFieldPickUpName.getText() + "\n" + jTextFieldPickUpAddess.getText() + "\n" + jTextFieldPickUpZipCode.getText() + " " + jTextFieldPickUpCity.getText();
                String endAddress = jTextFieldDeliveryName.getText() + "\n" + jTextFieldDeliveryAddress.getText() + "\n" + jTextFieldDeliveryZipCode.getText() + " " + jTextFieldDeliveryCity.getText();

                GoodsPriceHandler gph = new GoodsPriceHandler(databasse);
                Truck truck = (Truck) jComboBoxTrucks.getSelectedItem();
                Driver driver = (Driver) jComboBoxDrivers.getSelectedItem();
                ShipmentHandler sh = new ShipmentHandler(databasse);
                sh.addShipment(amount, date, dangerousGoods, goodsType, weight, comment, customer, startAddress, endAddress, truck, driver, route);
                fillComboTruck();
                fillComboDriver();
                jLOrderConfirm.setVisible(true);
            } catch (SQLException ex) {
                errorPopup("Kunne ikke oprette ordren i databasen.");
            }
        } else {
            errorPopup("Kontroller venligst at alle felter er udfyldt.");
        }
    }//GEN-LAST:event_jButtonCreateOrderActionPerformed

    private void jButtonCreateOrderMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonCreateOrderMouseExited
        jLOrderConfirm.setVisible(false);
    }//GEN-LAST:event_jButtonCreateOrderMouseExited

    private void jCheckBoxDangerousGoodsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxDangerousGoodsActionPerformed
        calculatePrice();
    }//GEN-LAST:event_jCheckBoxDangerousGoodsActionPerformed

    private void jRadioButtonSpecialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonSpecialActionPerformed
        calculatePrice();
        if (getSelectedGoodsType() == 0) {
            jLabelGoodsTypeMissing.setVisible(true);
        } else {
            jLabelGoodsTypeMissing.setVisible(false);
        }
    }//GEN-LAST:event_jRadioButtonSpecialActionPerformed

    private void jRadioButtonGeneralGoodsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonGeneralGoodsActionPerformed
        calculatePrice();
        if (getSelectedGoodsType() == 0) {
            jLabelGoodsTypeMissing.setVisible(true);
        } else {
            jLabelGoodsTypeMissing.setVisible(false);
        }
    }//GEN-LAST:event_jRadioButtonGeneralGoodsActionPerformed

    private void jRadioButtonPalletShippingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonPalletShippingActionPerformed
        calculatePrice();
        if (getSelectedGoodsType() == 0) {
            jLabelGoodsTypeMissing.setVisible(true);
        } else {
            jLabelGoodsTypeMissing.setVisible(false);
        }
    }//GEN-LAST:event_jRadioButtonPalletShippingActionPerformed

    private void jComboBoxRouteStopCityItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxRouteStopCityItemStateChanged
        getRoute(evt);
    }//GEN-LAST:event_jComboBoxRouteStopCityItemStateChanged

    private void jComboBoxRouteStartCityItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxRouteStartCityItemStateChanged

        if (jComboBoxRouteStartCity.getSelectedIndex() > 0 && jComboBoxRouteStartCity.getSelectedItem() != null && evt.getStateChange() == ItemEvent.SELECTED) {
            fillComboEndCity();
        }
        getRoute(evt);
    }//GEN-LAST:event_jComboBoxRouteStartCityItemStateChanged

    private void jComboBoxYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxYearActionPerformed
        fillComboDateChoice();
        fillComboCity();
        fillComboEndCity();
        jComboBoxYear.setBorder(emptyComboBoxBorder);
        if (jComboBoxRouteStartCity.getSelectedIndex() == 0 || jComboBoxRouteStopCity.getSelectedIndex() == 0) {
            jTextFieldKM.setText("0");
        } else {
            fillComboDriver();
            fillComboTruck();
        }
        dateCheck();
    }//GEN-LAST:event_jComboBoxYearActionPerformed

    private void jComboBoxMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxMonthActionPerformed

        fillComboDateChoice();
        fillComboCity();
        fillComboEndCity();
        jComboBoxMonth.setBorder(emptyComboBoxBorder);
        if (jComboBoxRouteStartCity.getSelectedIndex() == 0 || jComboBoxRouteStopCity.getSelectedIndex() == 0) {
            jTextFieldKM.setText("0");
        } else {
            fillComboDriver();
            fillComboTruck();
        }
        dateCheck();
    }//GEN-LAST:event_jComboBoxMonthActionPerformed

    private void jComboBoxDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxDateActionPerformed
        fillComboCity();
        fillComboEndCity();
        jComboBoxDate.setBorder(emptyComboBoxBorder);
        if (jComboBoxRouteStartCity.getSelectedIndex() == 0 || jComboBoxRouteStopCity.getSelectedIndex() == 0) {
            jTextFieldKM.setText("0");
        } else {
            fillComboDriver();
            fillComboTruck();
        }
        dateCheck();
    }//GEN-LAST:event_jComboBoxDateActionPerformed

    private void jButtonViewTrucksActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonViewTrucksActionPerformed
        jTabbedPane1.setSelectedIndex(3);
    }//GEN-LAST:event_jButtonViewTrucksActionPerformed

    private void jButtonConnectToDatabaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConnectToDatabaseActionPerformed
        jTabbedPane1.setSelectedIndex(5);
    }//GEN-LAST:event_jButtonConnectToDatabaseActionPerformed

    private void jButtonViewShippingOrdersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonViewShippingOrdersActionPerformed
        jTabbedPane1.setSelectedIndex(2);
        getShipments();
    }//GEN-LAST:event_jButtonViewShippingOrdersActionPerformed

    private void jButtonCreateShippingOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreateShippingOrderActionPerformed
        jTabbedPane1.setSelectedIndex(1);
    }//GEN-LAST:event_jButtonCreateShippingOrderActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        jTabbedPane1.setSelectedIndex(0);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButtonViewChauffuerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonViewChauffuerActionPerformed
        jTabbedPane1.setSelectedIndex(4);
    }//GEN-LAST:event_jButtonViewChauffuerActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if (jCheckBox1.isSelected()) {
            pickUpName = jTextFieldPickUpName.getText();
            pickUpAddress = jTextFieldPickUpAddess.getText();
            pickUpZipCode = jTextFieldPickUpZipCode.getText();
            pickUpCity = jTextFieldPickUpCity.getText();
            jTextFieldPickUpName.setText(jTextFieldClientName.getText());
            jTextFieldPickUpAddess.setText(jTextFieldClientAddress.getText());
            jTextFieldPickUpZipCode.setText(jTextFieldClientZipCode.getText());
            jTextFieldPickUpCity.setText(jTextFieldClientCity.getText());
        } else {
            jTextFieldPickUpName.setText(pickUpName);
            jTextFieldPickUpAddess.setText(pickUpAddress);
            jTextFieldPickUpZipCode.setText(pickUpZipCode);
            jTextFieldPickUpCity.setText(pickUpCity);
        }
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        if (jCheckBox2.isSelected()) {
            deliveryName = jTextFieldDeliveryName.getText();
            deliveryAddress = jTextFieldDeliveryAddress.getText();
            deliveryZipCode = jTextFieldDeliveryZipCode.getText();
            deliveryCity = jTextFieldDeliveryCity.getText();
            jTextFieldDeliveryName.setText(jTextFieldClientName.getText());
            jTextFieldDeliveryAddress.setText(jTextFieldClientAddress.getText());
            jTextFieldDeliveryZipCode.setText(jTextFieldClientZipCode.getText());
            jTextFieldDeliveryCity.setText(jTextFieldClientCity.getText());
        } else {
            jTextFieldDeliveryName.setText(deliveryName);
            jTextFieldDeliveryAddress.setText(deliveryAddress);
            jTextFieldDeliveryZipCode.setText(deliveryZipCode);
            jTextFieldDeliveryCity.setText(deliveryCity);
        }
    }//GEN-LAST:event_jCheckBox2ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        jTabbedPane1.setSelectedIndex(0);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jComboBoxTrucksActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxTrucksActionPerformed
        jComboBoxTrucks.setBorder(emptyComboBoxBorder);
    }//GEN-LAST:event_jComboBoxTrucksActionPerformed

    private void jComboBoxDriversActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxDriversActionPerformed
        jComboBoxDrivers.setBorder(emptyComboBoxBorder);
    }//GEN-LAST:event_jComboBoxDriversActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                WebLookAndFeel.install(); //WebLaf Look and Feel
                new MainGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jBClearAll;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButtonConnect;
    private javax.swing.JButton jButtonConnectToDatabase;
    private javax.swing.JButton jButtonCreateOrder;
    private javax.swing.JButton jButtonCreateShippingOrder;
    private javax.swing.JButton jButtonCreateShippingOrder1;
    private javax.swing.JButton jButtonGetShipments;
    private javax.swing.JButton jButtonViewChauffuer;
    private javax.swing.JButton jButtonViewShippingOrders;
    private javax.swing.JButton jButtonViewShippingOrders2;
    private javax.swing.JButton jButtonViewTrucks;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBoxDangerousGoods;
    private javax.swing.JComboBox jComboBoxDate;
    private javax.swing.JComboBox jComboBoxDrivers;
    private javax.swing.JComboBox jComboBoxMonth;
    private javax.swing.JComboBox jComboBoxRouteStartCity;
    private javax.swing.JComboBox jComboBoxRouteStopCity;
    private javax.swing.JComboBox jComboBoxTrucks;
    private javax.swing.JComboBox jComboBoxYear;
    private javax.swing.JLabel jLOrderConfirm;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelAmount;
    private javax.swing.JLabel jLabelConnection;
    private javax.swing.JLabel jLabelConnectionSuccess;
    private javax.swing.JLabel jLabelDayName;
    private javax.swing.JLabel jLabelGoodsTypeMissing;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JRadioButton jRadioButtonGeneralGoods;
    private javax.swing.JRadioButton jRadioButtonPalletShipping;
    private javax.swing.JRadioButton jRadioButtonSpecial;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTableDrivers;
    private javax.swing.JTable jTableOverviewShippingOrders2;
    private javax.swing.JTable jTableTrucks;
    private javax.swing.JTextArea jTextAreaRemarks;
    private javax.swing.JTextField jTextFieldAmount;
    private javax.swing.JTextField jTextFieldClientAddress;
    private javax.swing.JTextField jTextFieldClientCity;
    private javax.swing.JTextField jTextFieldClientName;
    private javax.swing.JTextField jTextFieldClientZipCode;
    private javax.swing.JTextField jTextFieldDatabaseName;
    private javax.swing.JTextField jTextFieldDeliveryAddress;
    private javax.swing.JTextField jTextFieldDeliveryCity;
    private javax.swing.JTextField jTextFieldDeliveryName;
    private javax.swing.JTextField jTextFieldDeliveryZipCode;
    private javax.swing.JTextField jTextFieldIPHostname;
    private javax.swing.JTextField jTextFieldKM;
    private javax.swing.JTextField jTextFieldPassWord;
    private javax.swing.JTextField jTextFieldPickUpAddess;
    private javax.swing.JTextField jTextFieldPickUpCity;
    private javax.swing.JTextField jTextFieldPickUpName;
    private javax.swing.JTextField jTextFieldPickUpZipCode;
    private javax.swing.JTextField jTextFieldPort;
    private javax.swing.JTextField jTextFieldPrice;
    private javax.swing.JTextField jTextFieldUserName;
    private javax.swing.JTextField jTextFieldWeight;
    // End of variables declaration//GEN-END:variables

}
